﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Data;

using System.Data.Common;
using Mocola.BLL;
using Mocola.Model;

namespace Mocola.Net.Web.ajax
{
    public partial class AddFile : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            MembershipCreateStatus status = new MembershipCreateStatus();
            DbTransaction transaction = Databases.MocolaNet.BeginTransaction(IsolationLevel.ReadCommitted);

            try
            {
                string pTid = getRequest("Tid");
                string pEid = getRequest("Eid");
                string pMingCheng = getRequest("MingCheng");        // 名称
                string pWenJianHao = getRequest("WenJianHao");      // 文件号
                string pShenQingHao = getRequest("ShenQingHao");    // 申请号
                string pJueDingHao = getRequest("JueDingHao");      // 决定号

                string pJiShouRiQi = getRequest("JieShouRiQi_Nian") + "-" + getRequest("JieShouRiQi_Yue") + "-" + getRequest("JieShouRiQi_Ri");      // 接收时间
                string pFaWenRiQi = getRequest("FaWenRiQi_Nian") + "-" + getRequest("FaWenRiQi_Yue") + "-" + getRequest("FaWenRiQi_Ri");      // 发文日期

                string pFaWenDanWei = getRequest("FaWenDanWei");        // 发文单位

                string pShuLiang = getRequest("ShuLiang");              // 数量

                string pZaiTi = getRequest("ZaiTi");                    // 载体

                string pCaiZhi = getRequest("CaiZhi");                  // 材质
                string pMiJi = getRequest("MiJi");                      // 密级
                string pBaoGuanQiXian = getRequest("BaoGuanQiXian");    // 保管期限

                string pZhuangTai = getRequest("ZhuangTai");            // 状态
                string pBeiZhu = getRequest("BeiZhu");                  // 备注

                int nID = Databases.MocolaNet.Insert(Moc_FilesInfo.Moc_Files)
                                 .AddColumn(Moc_FilesInfo.Moc_Files.Name, pMingCheng)
                                 .AddColumn(Moc_FilesInfo.Moc_Files.JueDingHao, pJueDingHao)
                                 .AddColumn(Moc_FilesInfo.Moc_Files.WenJianHao, pWenJianHao)
                                 .AddColumn(Moc_FilesInfo.Moc_Files.ShenQingHao, pShenQingHao)
                                 .AddColumn(Moc_FilesInfo.Moc_Files.FaWenRiQi, pFaWenRiQi)
                                 .AddColumn(Moc_FilesInfo.Moc_Files.FaWenDanWei, pFaWenDanWei)
                                 .AddColumn(Moc_FilesInfo.Moc_Files.ShuLiang, pShuLiang)
                                 .AddColumn(Moc_FilesInfo.Moc_Files.ZaiTi, pZaiTi)
                                 .AddColumn(Moc_FilesInfo.Moc_Files.CaiZhi, pCaiZhi)
                                 .AddColumn(Moc_FilesInfo.Moc_Files.MiJi, pMiJi)
                                 .AddColumn(Moc_FilesInfo.Moc_Files.BaoGuanQiXian, pBaoGuanQiXian)
                                 .AddColumn(Moc_FilesInfo.Moc_Files.ZhuangTai, pZhuangTai)
                               //.AddColumn(Moc_FilesInfo.Moc_Files.FaQiBuMen, pFaQiBuMen)
                               //.AddColumn(Moc_FilesInfo.Moc_Files.YiJiaoRen, pYiJiaoRen)
                               //.AddColumn(Moc_FilesInfo.Moc_Files.JiShouRen, pJiShouRen)
                                 .AddColumn(Moc_FilesInfo.Moc_Files.JieShouRiQi, pJiShouRiQi)
                                 .AddColumn(Moc_FilesInfo.Moc_Files.BeiZhu, pBeiZhu)
                                 .AddColumn(Moc_FilesInfo.Moc_Files.Eid, pEid)
                                 .AddColumn(Moc_FilesInfo.Moc_Files.Tid, pTid)
                                 .SetTransaction(transaction)
                                 .ExecuteReturnAutoIncrementID(Moc_FilesInfo.Moc_Files.ID);

                bool blTrees = false;

                if (nID != -1)
                {
                    blTrees = true;
                }


                if (blTrees)
                {
                    Response.Write("新增文件成功！");
                    status = MembershipCreateStatus.Success;
                }
                else
                {
                    Response.Write("新增文件失败！");
                    status = MembershipCreateStatus.ProviderError;
                }
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
                status = MembershipCreateStatus.ProviderError;
            }
            finally
            {
                if (status == MembershipCreateStatus.Success)
                    transaction.Commit();
                else
                    transaction.Rollback();
                Databases.MocolaNet.CloseConnection(transaction);
            }
        }

        private string getRequest(string pReqID)
        {
            return string.IsNullOrEmpty(Request.Form[pReqID]) ? string.Empty : Request.Form[pReqID].ToString();
        }
    }
}
